<template>
    <double-right-outlined v-show="!visible" @click="visible = true" />
    <a-drawer class="box" v-model:visible="visible" width="16em" :mask="false" :destroyOnClose="true" placement="left"
        :closable='false'>
        <p>图层目录</p>
        <a-tree v-model:expandedKeys="expandedKeys" v-model:checkedKeys="checkedKeys" checkable :tree-data="treeData"
            @check="handleCheckChange">
            <template #title="{ title, key }">
                <span>{{ title }}</span>
            </template>
        </a-tree>
        <double-left-outlined @click="visible = false" />
    </a-drawer>
</template>

<script setup>
/* 图标 */
import { DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons-vue';
/* 封装的目录树 */
import { ZondyDocCatalog } from 'assets/libs/utils/catalog.js'
import { onMounted, ref } from 'vue';
/*目录树初始状态 */
const visible = ref(false);
const treeData = ref([{
    title: '光谷智慧交通',
    key: '0-0',
    children: [],
}])
const expandedKeys = ref(['0-0']);
const checkedKeys = ref(['0-0']);
// 控制图层显隐
function handleCheckChange(data, e) {
    // console.log(data, e);
    // console.log(e.node.key);
    if (data.length == 0) {
        treeData.value[0].children.map(item => {
            // console.log(item.key);
            setTimeout(() => {
                docLayer.setLayerStatus(item.key, 'exclude');
            }, 20 * item.key);
        })
    } else if (data.length == 6) {
        treeData.value[0].children.map(item => {
            // console.log(item.key);
            setTimeout(() => {
                docLayer.setLayerStatus(item.key, 'include');
            }, 20 * item.key);
        })
    } else if (e.checked) {
        //获取原型上的doclayer，选择状态不能用show和hide，要用include和exclude
        docLayer.setLayerStatus(e.node.key, 'include');
    } else {
        //没有选中状态
        docLayer.setLayerStatus(e.node.key, 'exclude');
    }
}
onMounted(() => {
    /* 拿到地图文档所有图层 */
    ZondyDocCatalog.getLayer({
        callback: (data) => {
            // console.log(data);
            data.value.forEach((item) => {
                // console.log(item);
                /* 把数据渲染到目录树 */
                treeData.value[0].children.push({
                    key: item.LayerIndex,
                    title: item.Name,
                });
            })
        }
    })
    // getTreeData()
})
</script>

<style lang="scss" scoped>
img {
    width: 39px;
    height: 39px;
    rotate: y 45deg;
}

p {
    font-size: 24px;
    padding-left: 20px;
    color: #fff;
    margin: 0;
    padding: 8px 20px;
    background-color: #409eff;
}
</style>
<style>
.ant-tree {
    margin-top: 10px;
    font-size: 16px;
    background-color: rgba(0, 0, 0, 0);
    position: relative;
}

.ant-drawer {
    position: fixed;
    height: 25rem;
    top: 5em;
}

.ant-drawer-body {
    padding: 0;
}

.anticon-double-left {
    position: absolute;
    top: 14px;
    right: 10px;
    transform: translateUY(-50%);
}

.anticon-double-left svg {
    color: #fff;
    width: 2em;
    height: 2em;
}

.anticon-double-right {
    position: fixed;
    height: 54px;
    width: 54px;
    top: 5em;
    background-color: #409eff;
    display: flex;
    justify-content: center;
    align-items: center;
}

.anticon-double-right svg {
    color: #fff;
    width: 2em;
    height: 2em;
}
</style>